Skip to content

Fix PHP 8.5 deprecations: roman_year nullable + (double)→(float) cast#2

Closed
luca9692 wants to merge 2 commits into
padosoft:masterfrom
luca9692:master
Closed

Fix PHP 8.5 deprecations: roman_year nullable + (double)→(float) cast#2
luca9692 wants to merge 2 commits into
padosoft:masterfrom
luca9692:master

Conversation

@luca9692
Copy link
Copy Markdown

What

Two PHP 8.5 deprecation fixes:

  1. src/datetime.php:212roman_year(int $year = null)roman_year(?int $year = null) (PHP 8.4+ requires explicit nullable on non-nullable type with default null)
  2. src/validation.php:130(double)$value cast → (float)$value (PHP 8.5 deprecates non-canonical (double) cast)

Why

Used by gescat-laravel on PHP 8.5 — these surface as runtime Deprecated notices and will become fatal in PHP 8.6+.

Compatibility

Both changes are semantic no-ops (same behavior, explicit syntax). No breaking changes.

Patches

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses PHP 8.5 deprecation notices by updating two helper functions in the support library to use canonical/explicit typing and casting syntax.

Changes:

  • Update roman_year() to explicitly accept nullable input (?int $year = null) to avoid deprecation for non-nullable typed params with null defaults.
  • Replace deprecated (double)$value cast with canonical (float)$value in isIntegerFloatingPoint().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/datetime.php Makes roman_year() parameter explicitly nullable to avoid PHP 8.4+ deprecation notices.
src/validation.php Switches (double) to (float) cast in integer-floating-point validation logic for PHP 8.5 compatibility.
Comments suppressed due to low confidence (1)

src/datetime.php:216

  • Now that the parameter is typed as ?int, the is_numeric($year) check is effectively just a null check (ints are always numeric). Using $year === null (or renaming the condition/comment) would make the intent clearer and avoid implying non-int inputs are expected.
function roman_year(?int $year = null): string
{
    if (!is_numeric($year)) {
        $year = (int)date('Y');
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/validation.php
Comment on lines +130 to 131
&& ((int)((float)$value) == $value || (int)$value == $value || strpos(strtoupper((string)$value),
'E') === false);
@lopadova
Copy link
Copy Markdown
Contributor

Grazie @luca9692 per il contributo! 🙏

Entrambe le tue fix (roman_year?int e (double)(float)) sono corrette e le abbiamo incorporate. Da sole però non bastavano per un run pulito su PHP 8.5: mancavano altri due punti emersi nei test su 8.5:

  • isIntegerFloatingPoint() emetteva il nuovo warning "float not representable as int" sul cast (int)((float)$value) al confine di PHP_INT_MAX;
  • xml_parser_free() è deprecata in 8.5 (no-op dal 8.0).

Abbiamo quindi aperto #3 che include le tue modifiche + questi fix aggiuntivi, il bump di sicurezza di PHPUnit (^9.6.33) e una nuova CI matrix GitHub Actions 8.0→8.5. Chiudo questa in favore di #3 (i tuoi commit sono accreditati).

@lopadova lopadova closed this May 28, 2026
lopadova added a commit that referenced this pull request May 28, 2026
- Support PHP up to 8.5 (php constraint ^7.0|^8.0); tested 8.0-8.5
- New GitHub Actions test matrix (PHP 8.0-8.5); decommission CircleCI/Travis/Scrutinizer
- Bump phpunit to ^9.6.33 (security: unsafe deserialization in PHPT coverage, GHSA)
- PHP 8.5 deprecation fixes: roman_year ?int, (double)->(float),
  guard out-of-range int casts in isIntegerFloatingPoint, skip xml_parser_free() on PHP >= 8.0
- Tag network-dependent tests @group network, excluded in CI
- README: remove broken Scrutinizer/Travis badges, add Tests badge

Incorporates and supersedes #2 (PHP 8.5 deprecation fixes by @luca9692).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants